from flask_wtf import FlaskForm
from wtforms import PasswordField, StringField, SubmitField, IntegerField, SelectField
from wtforms.validators import DataRequired, Length, EqualTo, Optional, Email, Regexp, NumberRange


class PasswordChangeForm(FlaskForm):
    password = PasswordField(label="旧密码",
                             validators=[DataRequired(), Length(min=6, max=12, message="输入长度在须6-12个字符之间！！")])
    newpassword = PasswordField(label="密码",
                                validators=[DataRequired(), Length(min=6, max=12, message="输入长度在须6-12个字符之间！！")])
    newpassword1 = PasswordField(label="新密码",
                                 validators=[DataRequired(), Length(min=6, max=12, message="输入长度在须6-12个字符之间！！"),
                                             EqualTo(fieldname='newpassword', message="两次密码不一致")])
    submit = SubmitField("提交")


class UserInfoForm(FlaskForm):
    email = StringField(label="邮箱", validators=[Optional(), Email(message="请输入正确的邮箱地址")])
    phone = StringField(label="手机号", validators=[
        Regexp(r'^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$', message="请输入合法手机号")])
    submit = SubmitField("提交")


class RegisterForm(FlaskForm):
    name = StringField(label="用户名", validators=[DataRequired(), Length(min=6, max=16, message="输入长度在须6-16个字符之间！！")])
    submit = SubmitField("提交")


class NameForm(FlaskForm):
    name = StringField(label="姓名", validators=[DataRequired()])
    age = IntegerField(label="年龄", validators=[DataRequired(), NumberRange(min=1, max=100)])
    # phone = IntegerField(label="手机号",validators = [DataRequired(),Regexp(r'^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}')])
    select = SelectField(choices=[['1', '医生'], ['2', '学生'], ])
    submit = SubmitField("提交")

